package com.tourManagement.controller;
import com.tourManagement.entity.RT;
import com.tourManagement.entity.Sight;
import com.tourManagement.service.SightService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

@RestController
@RequestMapping("/sight")
@AllArgsConstructor
public class SightController {

    private SightService sightService;//创建SightService

    @GetMapping("/getSights")
    public RT getSights() throws SQLException {
        return RT.success(sightService.getAll());
    }

    @PostMapping("/update")
    public RT updateSight(@RequestBody Sight data) throws SQLException {
        if(data.getSightName().isEmpty()) {
            return RT.error("景区名字不能为空");
        }
        return RT.success(sightService.update(data));
    }

    @PostMapping("/insert")
    public RT insert(@RequestBody Sight data) throws SQLException {
        if(data.getSightName().isEmpty()) {
            return RT.error("景区名字不能为空");
        }
        return RT.success(sightService.insert(data));
    }

    @GetMapping("/selectOne")
    public RT selectOne(Integer id) throws SQLException {
        return RT.success( sightService.selectOne(id) );
    }

    @GetMapping("/delete")
    public RT delete(Integer id) throws SQLException {
        return RT.success(sightService.delete(id));
    }
}
